package main

// 工厂方法将 goroutine 和 channel 绑定

// 使用命名返回参数
func newRecv[T any](cap int) (data chan T, done chan struct{}) {
	data = make(chan T, cap)
	done = make(chan struct{})

	go func() {
		defer close(done)

		for v := range data {
			println(v)
		}

	}()

	return
}

func getVal() int {
	return 1
}

func main() {

	data, done := newRecv[int](3)

	for i := 0; i < 10; i++ {
		data <- i
	}

	close(data)

	<-done
}
